package com.mall.security.service.impl;

import com.mall.security.entity.MyUserDetails;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
 * @author WanMing
 * @date 2021/3/18 0:12
 */
@Service
public class UserDetailImpl implements UserDetailsService {



    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        System.out.println(username);
        if("wan".equals(username)){
            MyUserDetails myUserDetails = new MyUserDetails();
            myUserDetails.setId(1L);
            myUserDetails.setUsername("wan");
            myUserDetails.setPassword(new BCryptPasswordEncoder().encode("111"));
            myUserDetails.setAuthorities(Arrays.asList(new SimpleGrantedAuthority("add_user")));
            return myUserDetails;
        }
       return null;
    }
}
